<?php

class AjusteController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			);
	}



	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			/*array('allow',  
				'actions'=>array('index','view','assign'),
				'users'=>array('*'),
				),*/
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('index'),
			    //'users'=>array('@'),
				'roles'=>array('Administrador'),
				),
			/*array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('@'),
				),*/
			array('deny',  // deny all users
				'users'=>array('*'),
				),
			);
	}

	
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$model=new AjusteForm;
		if (isset($_POST['AjusteForm'])) 
		{
			$model->attributes = $_POST['AjusteForm'];
			if($model->validate())
			{
				if ($model->ajustar())
				 {
					Yii::app()->user->setFlash('success', 'Ajuste de inventario realizado con éxito.');
					$model = new AjusteForm;
				}
				else
				{
					Yii::app()->user->setFlash('error', 'No se logró realizar el ajuste de inventario.');
				}
			}
		}
		$this->render('index', array('model' => $model, ));
	}
}
